<template>
	<view>
		<u-navbar title-size="34" leftIconColor="#343A40" title="草稿箱" title-color="#343A40" :border-bottom="false"
			:custom-back="tui.goBack"></u-navbar>
		<view class="text-ADB5BD fz-24 draft-title">草稿中的作品仅对自己可见</view>
		<view class="d-flex hot-box">
			<view class="tab-list" v-for="(item,index) in draftList" :class="{'mxx-auto':index % 3 ==1}" @click="toUpdateWorks(item)">
				<image :src="item.cover" mode="aspectFill" v-if="item.type != 1"></image>
				<image :src="item.file" mode="aspectFill" v-else></image>
			</view>
		</view>
		<u-loadmore :status="status" v-show="loading" margin-top="50" class="pb-4"  /> 
		<view class="no-works" v-show="total === 0 && !loading">
			<image src="/static/market/no-works.png" mode="aspectFill"></image>
			<view style="color: #b5b5b5;">空空如也~</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading:false,
				status:'loading',
				total: '',
				page: 1,
			}
		},
		onLoad() {
			this.getDraftList()
		},
		computed: {
			draftList() {
				return this.$store.state.works.draftList
			}
		},
		onReachBottom() {
			if(this.draftList.length < this.total){
				this.page ++
				this.getDraftList()
			}
		},
		methods: {
			//前往修改草稿箱
			toUpdateWorks(item){
				if(item.cover){
					uni.navigateTo({
						url:`/pages/secondary/creation/updateAudio?work_id=${item.id}&name=${item.name}&file=${item.file}&category_id=${item.category_id}&album_id=${item.album_id}&category_name=${item.category.name}&album_name=${item.album.name}&cover=${item.cover}`
					})
				}else{
					uni.navigateTo({
						url:`/pages/secondary/creation/update?work_id=${item.id}&name=${item.name}&file=${item.file}&category_id=${item.category_id}&album_id=${item.album_id}&category_name=${item.category.name}&album_name=${item.album.name}`
					})
				}
			},
			//我的作品
			getDraftList() {
				this.loading = true
				this.status = 'loading'
				this.$store.dispatch('works/work', { status: 0,page:this.page }).then(res => {
					this.total = res.data.total
					if(this.draftList.length == this.total && this.page > 1){
						this.status = 'nomore'
					}else{
						this.loading = false
					}
				}).catch(error=>{
					this.loading = false
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.type-wrap {
		width: 100%;
		padding: 30upx;
		box-sizing: border-box;
	}

	.draft-title {
		padding: 29upx 29upx 0;
		box-sizing: border-box;
	}

	.hot-box {
		width: 100%;
		padding: 39upx 30upx 0;
		box-sizing: border-box;
		flex-wrap: wrap;

		.tab-list {
			width: 220upx;
			height: 220upx;
			margin-bottom: 16upx;
			image {
				width: 220upx;
				height: 220upx;
				border-radius: 8upx;
			}
		}
		.mxx-auto{
			margin-left: 15upx;
			margin-right: 15upx;
		}
	}
	.recordNo-icon {
		width: 206upx;
		height: 136upx;
		margin: 130upx auto 35upx;
	
		image {
			width: 206upx;
			height: 136upx;
			vertical-align: top;
		}
	}
	.no-works{
		margin: 50upx auto;
		text-align: center;
		image{
			width: 300upx;
			height: 300upx;
		}
	}
</style>
